#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


char map[45][45];
int map_d[45][45];
int Min(int a, int b)
{
	return a <= b ? a : b;
}

void dfs_deal(int x, int y, int i, int j)
{
	if (map_d[i + 1][j] == 0){
		map_d[i + 1][j] = map_d[i][j] + 1;
		dfs_deal(x, y, i + 1, j);
	}
	if (map_d[i - 1][j] == 0) {
		map_d[i - 1][j] = map_d[i][j] + 1;
		dfs_deal(x, y, i - 1, j);
	}
	if (map_d[i][j + 1] == 0) {
		map_d[i][j + 1] = map_d[i][j] + 1;
		dfs_deal(x, y, i, j + 1);
	}
	if (map_d[i][j - 1] == 0) {
		map_d[i][j - 1] = map_d[i][j] + 1;
		dfs_deal(x, y, i, j - 1);
	}
	if (map_d[i + 1][j] > 0 && map_d[i][j] + 1 < map_d[i + 1][j]) {
		map_d[i + 1][j] = map[i][j] + 1;
		dfs_deal(x, y, i + 1, j);
	}
	if (map_d[i - 1][j] > 0 && map_d[i][j] + 1 < map_d[i - 1][j]) {
		map_d[i - 1][j] = map[i][j] + 1;
		dfs_deal(x, y, i - 1, j);
	}
	if (map_d[i][j + 1] > 0 && map_d[i][j] + 1 < map_d[i][j + 1]) {
		map_d[i][j + 1] = map[i][j] + 1;
		dfs_deal(x, y, i, j + 1);
	}
	if (map_d[i][j - 1] > 0 && map_d[i][j] + 1 < map_d[i][j - 1]) {
		map_d[i][j - 1] = map[i][j] + 1;
		dfs_deal(x, y, i, j - 1);
	}
	
}
int main()
{
	int x, y;
	scanf("%d%d\n", &x, &y);
	for (int i = 0; i <= x + 1; i++)map_d[i][0] = -1;
	for (int j = 0; j <= y + 1; j++)map_d[0][j] = -1;
	for (int i = 0; i <= x + 1; i++)map_d[i][y + 1] = -1;
	for (int j = 0; j <= y + 1; j++)map_d[x + 1][j] = -1;
	for (int i = 1; i <= x; i++) {
		for (int j = 1; j <= y; j++) {
			scanf("%c", &map[i][j]);
			if (map[i][j] == '#')map_d[i][j] = -1;
		}
		if (i != x)scanf("\n");
	}
	map_d[1][1] = 1;
	dfs_deal(x, y, 1, 1);
	printf("%d", map_d[x][y]);
	return 0;
}







//int main()
//{
//	int x, y;
//	scanf("%d%d\n", &x, &y);
//	for (int i = 1; i <= x; i++) {
//		for (int j = 1; j <= y; j++) {
//			scanf("%c", &map[i][j]);
//		}
//		if (i != x)scanf("\n");
//	}
//	for (int i = 1; i <= x; i++) {
//		for (int j = 1; j <= y; j++) {
//			if (map[i][j] == '.') {
//				if (map[i - 1][j] == '.' && map[i][j - 1] == '#')map_d[i][j] = map_d[i - 1][j] + 1;
//				else if (map[i - 1][j] == '#' && map[i][j - 1] == '.')map_d[i][j] = map_d[i][j - 1] + 1;
//				else map_d[i][j] = Min(map_d[i - 1][j], map_d[i][j - 1]) + 1;
//			}
//		}
//	}
//	printf("%d", map_d[x][y]);
//	return 0;
//}